<%@ page import="java.util.*" %>
<%@ page import="org.tigr.htc.persist.*" %>
<%@ page import="org.tigr.htc.common.*" %>
<%@ page import="org.tigr.htc.cmd.*" %>

<%!
    static String[] colors = new String[] { "#ececec", "#dc9000" };
%>
<html>
<head>
<title> Display Task List 2 </title>
</head>

<body>
<%@ include file="header.jsp"%>
<font size=+2 face="arial,helvetica,sanserif" >Display Task List </font>
<font size=-1>

<form method="get" action="task_display.jsp">
    change to id <input type="text" name="RequestID" value=""/>&nbsp;<input type="submit" value="GO" /><br>
<br>
</form>
<%
// IPersist pl = PersistFactory.getIPersist();
IPersist pl = DirectDatabase.getInstance();
long id = -1;
Command cmd = null;

int range = 100;
String s_range = request.getParameter("Range");
if(s_range != null) {
  try {
	range = Integer.parseInt(s_range);
  } catch (Exception e) {
	range = 100;
  }
}

String sid = request.getParameter("RequestID");

if(sid != null) { // display default page
    id = Long.parseLong(sid);
    try {
      cmd = (Command) pl.find(id, Command.class);
    } catch (RuntimeException e) {
	e.printStackTrace();
%>
	exception with <%=e %>
<%	
     }

    }
    if(cmd != null) {
    	// As the command is not null force the command to load tasks
    	Vector tasks = pl.retrieveTasks(id);
    	cmd.setTasks(tasks);
	int nt = cmd.getNumTasks();
%>
Task Jump List:
<%
	for(int i = 0; i < nt; i += 100) {
%>
<a href="task_display.jsp?RequestID=<%=sid %>&Range=<%=(i + 100) %>"> <%=(i) %> - <%=(i + 99) %></a>&nbsp;

        <% } %>

  <table border=1 cellspacing=0 cellpadding=3 >
    <tr bgcolor="#000000"><td colspan=7><font color="white"><strong>Task List for <%=id %>  Total <%=nt %></strong></font></td></tr>
    <tr bgcolor="#c0c0f0"><td>Index</td><td>Machine</td><td>State</td><td>Worker</td><td>Return Value</td><td>Message</td></tr>

<%
	Task task;

	
	for(int i = (range - 100); i < range; i++) {
	   task = cmd.getTask(i);
           String bb = "http://intranet.tigr.org/sysadmin/bb/html/";	  
	   if(task != null) {
		if(task.machine.endsWith(".tigr.org")) {
             		bb += task.machine;
                } else {
			bb += task.machine + ".tigr.org";
                }
%>
    <tr>
    <td><%=task.index %></td>
    <td><%=task.machine %> <a href="<%=bb %>.cpu.html">CPU</a>  <a href="<%=bb %>.memory.html">MEM</a></td>
    <td><%=task.state %></td>
    <td><%=task.worker %></td>
    <td><%=task.returnValue %></td>
    <td><%=task.message %></td>
    </tr>

      <%  } else {  %>
    <tr>
    <td><%=i %></td>
    <td colspan=5>waiting</td>
    </tr>
       <% } %>
 <% } %>
    </table>	
 <% } %>


<jsp:include page="footer.jsp" flush="true"></jsp:include>
</body>
</html>
